//
//  dengluViewController.m
//  ui豆瓣
//
//  Created by lirui on 15/12/24.
//  Copyright © 2015年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "dengluViewController.h"
#import "LTview.h"
#import "zhuceViewController.h"
@interface dengluViewController ()
@property(nonatomic, retain)LTview *user;
@end

@implementation dengluViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [ UIColor whiteColor];
    self.navigationItem.title = @"用户登录";
    //xib
    self.user = [[[NSBundle mainBundle] loadNibNamed:@"LTView" owner:self options:nil] lastObject];
    self.user.center = CGPointMake(self.view.center.x, 200);
    [self.view addSubview:self.user];
    
//    self.navigationItem.leftBarButtonItem = [[ UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(back:)];
   
    UIButton *button = [ UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 50, 50);
    [button setTitleColor:[ UIColor blackColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"返回" forState:UIControlStateNormal];
    [self.view addSubview:button];
    
    UIBarButtonItem *buttonback = [[ UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = buttonback;
    
    
    [self.user.buttonregister addTarget:self action:@selector(zhuce) forControlEvents:UIControlEventTouchUpInside];
    
    [self.user.buttonenter addTarget:self action:@selector(enter) forControlEvents:UIControlEventTouchUpInside];
    
}
-(void)enter
{     if(self.user.nametextfield.text.length > 0 && self.user.pwdtextfield.text.length >0){
    [[NSUserDefaults standardUserDefaults] setObject:@"yes" forKey:@"states"];
    [[NSUserDefaults standardUserDefaults] synchronize];
        [self dismissViewControllerAnimated:YES completion:^{
            NSLog(@"登录成功");
       }];


}
    
}

-(void)zhuce
{   zhuceViewController *zhuce = [[ zhuceViewController alloc] init];
    __weak dengluViewController  *vc= self;
    void(^block)(NSString *) = ^(NSString *str){
        vc.user.nametextfield.text = str;
        
    };
    void(^block1)(NSString *) = ^(NSString *str1)
    {
        vc.user.pwdtextfield.text = str1;
    };
    zhuce.textblock = block;
    zhuce.pwdblock = block1;
    [self.navigationController pushViewController:zhuce animated:YES];
}



-(void)back:(UIBarButtonItem *)right
{
    [self dismissViewControllerAnimated:YES completion:^{
        NSLog(@"返回");
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
